package com.bafa.front.events;

import java.net.URL;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bafa.debug.Debug;
import com.bafa.jdbc.DBAccess;
import com.bafa.objects.PageBean;
import com.bafa.services.RetrieveServices;
import com.google.gdata.client.photos.PicasawebService;

public class DeletePhotoEvent extends Event {

	@Override
	public void doEvent(HttpServletRequest request,
			HttpServletResponse response, PageBean page) {
		// TODO Auto-generated method stub

		try{
			PicasawebService myService = new PicasawebService("bafa-test-2");
		
		myService.setUserCredentials("r.hmeid@gmail.com", "socrat3s");

		URL postUrl =
		  new URL("http://picasaweb.google.com/data/entry/api/user/r.hmeid/album/bafa/photoid/"+RetrieveServices.getPhotoId(request.getParameter("photoname"))+"/"+RetrieveServices.getPhotoVersion(request.getParameter("photoname")));
Debug.debug(this.getClass(),"doEvent","URL IS "+postUrl.getPath());
		myService.delete(postUrl);
		PreparedStatement updateTeam = new DBAccess().conn.prepareStatement("delete from photos where id=?");
		updateTeam.setString(1,request.getParameter("photoname"));
		updateTeam.execute();
		}catch(Exception e){
			Debug.printStackTrace(e);
		}
	}

}
